/*********************************************************************
 * PhPaperBAll. Clase para PaperBall.
 * Programación Multimedia y Juegos
 * Autor: David Vallejo Fernández    david.vallejo@tegnix.com
 * Autor: Carlos González Morcillo   carlos.gonzalez@tegnix.com
 *
 * You can redistribute and/or modify this file under the terms of the
 * GNU General Public License ad published by the Free Software
 * Foundation, either version 3 of the License, or (at your option)
 * and later version. See <http://www.gnu.org/licenses/>.
 *
 * This file is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.  
 *********************************************************************/

package physic;

import aze.display.TileSprite;
import aze.display.TileLayer;

import phx.World;
import phx.Shape;

class PhPaperBall extends PhSprite {

  // Create Shape =================================================
  override function createShape():Shape {
    return (new phx.Polygon([new phx.Vector(1,12), 
    			     new phx.Vector(1,17), 
    			     new phx.Vector(7,30), 
    			     new phx.Vector(20,30), 
    			     new phx.Vector(25,29), 
    			     new phx.Vector(29,19), 
    			     new phx.Vector(28,12), 
    			     new phx.Vector(17,2), 
  			     new phx.Vector(7,6)], 
			    new phx.Vector(-16,-16)));
  }

  // Constructor ==================================================
  public function new(id:String, l:TileLayer, w:World, px:Float, 
		      py:Float, vect:phx.Vector):Void {
    super(id, l, w, px, py, true, vect); 
  }

  // Check Collision ==============================================
  public function checkCollision(idBase:Int):Bool {
    for (a in _body.arbiters.iterator())
      if ((a.s1.id == idBase) || (a.s2.id == idBase)) return true;

    return false;
  }

  // Update =======================================================
  override public function update(w:Int, h:Int):Bool {
    x = _body.x;  y = _body.y;  rotation = _body.a;
    _body.updatePhysics();
    return true;
  }
}